using System;
using System.Collections.Generic;
using System.Text;
using CarlosAg.ExcelXmlWriter;

namespace TestImport.View.Lijsten
{

    class MaakExcelWerkboek
    {
        private String bestandsNaam;
        private Workbook book;
        private Worksheet sheet;
        private WorksheetStyle Default;
        private WorksheetStyle s24;
        private WorksheetStyle s28;
        private WorksheetStyle s29;
        private WorksheetStyle s30;

        public MaakExcelWerkboek(String bestandsNaam)
        {
            this.bestandsNaam = bestandsNaam;
            Generate();
        }

        public void Generate()
        {
            book = new Workbook();
            // -----------------------------------------------
            //  Properties
            // -----------------------------------------------
            book.Properties.Author = "";
            book.Properties.LastAuthor = "";
            book.Properties.Created = new System.DateTime(2009, 4, 28, 13, 36, 10, 0);
            book.Properties.Version = "11.5606";
            book.ExcelWorkbook.WindowHeight = 9210;
            book.ExcelWorkbook.WindowWidth = 19035;
            book.ExcelWorkbook.WindowTopX = 0;
            book.ExcelWorkbook.WindowTopY = 60;
            book.ExcelWorkbook.ProtectWindows = false;
            book.ExcelWorkbook.ProtectStructure = false;
            // -----------------------------------------------
            //  Generate Styles
            // -----------------------------------------------
            this.GenerateStyles(book.Styles);
            // -----------------------------------------------
            //  Generate Adressen Worksheet
            // -----------------------------------------------
            //this.GenerateWorksheetAdressen(book.Worksheets);
            //book.Save(filename);
        }

        private void GenerateStyles(WorksheetStyleCollection styles)
        {
            // -----------------------------------------------
            //  Default
            // -----------------------------------------------
            Default = styles.Add("Default");
            Default.Name = "Normal";
            Default.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            // -----------------------------------------------
            //  s24
            // -----------------------------------------------
            s24 = styles.Add("s24");
            s24.Font.Bold = true;
            s24.Font.Size = 14;
            s24.Interior.Color = "#C0C0C0";
            s24.Interior.Pattern = StyleInteriorPattern.Solid;
            s24.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            s24.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            s24.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            s24.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  s28
            // -----------------------------------------------
            s28 = styles.Add("s28");
            s28.Font.Italic = true;
            s28.Font.Size = 14;
            s28.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            s28.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            s28.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            s28.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  s29
            // -----------------------------------------------
            s29 = styles.Add("s29");
            s29.Font.Bold = true;
            s29.Font.Size = 14;
            s29.Font.Color = "#FF0000";
            s29.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            s29.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            s29.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            s29.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  s30
            // -----------------------------------------------
            s30 = styles.Add("s30");
            s30.Font.Bold = true;
            s30.Font.Size = 14;
            s30.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            s30.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            s30.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            s30.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
        }

        public void AddWorkSheet(WorksheetCollection sheets,String naam, int [] kolommen, int aRijen)
        {
            sheet = sheets.Add(naam);
            sheet.Table.ExpandedColumnCount = kolommen.Length;
            sheet.Table.ExpandedRowCount = aRijen;
            sheet.Table.FullColumns = 1;
            sheet.Table.FullRows = 1;
            foreach (int breedte in kolommen)
                sheet.Table.Columns.Add(breedte);
           
            // -----------------------------------------------
           /* WorksheetRow Row0 = sheet.Table.Rows.Add();
            Row0.Height = 18;
            Row0.Cells.Add("Naam", DataType.String, "s24");
            Row0.Cells.Add("Adres", DataType.String, "s24");
            */
            // -----------------------------------------------

            // -----------------------------------------------
            //  Options
            // -----------------------------------------------
            sheet.Options.Selected = true;
            sheet.Options.ProtectObjects = false;
            sheet.Options.ProtectScenarios = false;
            sheet.Options.PageSetup.PageMargins.Bottom = 0.984252F;
            sheet.Options.PageSetup.PageMargins.Left = 0.7874016F;
            sheet.Options.PageSetup.PageMargins.Right = 0.7874016F;
            sheet.Options.PageSetup.PageMargins.Top = 0.984252F;
            sheet.Options.Print.PaperSizeIndex = 9;
            sheet.Options.Print.HorizontalResolution = 300;
            sheet.Options.Print.VerticalResolution = 300;
            sheet.Options.Print.ValidPrinterInfo = true;
        }

        public void AddLine(string naam, string adres)
        {
            WorksheetRow Row = sheet.Table.Rows.Add();
            Row.Cells.Add(naam, DataType.String, "s30");
            Row.Cells.Add(adres, DataType.String, "s28");
            Row.Height = 20;
            Row.AutoFitHeight = false;

        }

       

        public void saveWorkBook()
        {
            try
            {
                book.Save(bestandsNaam);
            }
            catch (Exception ex) { };
        }
    }
}
